package chapter02;

public class Test04_Package {
    public static void main(String[] args) {
        Person p = new Person();
        p.setAge(20);
        System.out.println(p.getAge());
        p.setName("张三");
        System.out.println(p.getName());
    }
}
class Person{
    //私有限制只能在类的内部取得
    private String name;
    private int age;
    //使用public限制的能够在任意地方被访问
    public void setAge(int number){
        if(number<0||number>120){
            System.out.println("你输入的年龄有误");
        }else{
            age = number;
        }
    }
    public int getAge(){
        return age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
